class Node {
    constructor(value, next = null) {
        this.value = value;
        this.next = next;
    }
}

class MyQueueForLinkList {
    constructor() {
        this.head = null; //一个用于记录头节点
        this.tail = null; //一个用于记录尾节点
        this._size = 0; //一个用于记录链表长度,设置成私有属性   
    }
    
    push(element) {
        const newNode = new Node(element);
        if (this.isEmpty()) {
            this.head = newNode;
            this.tail = newNode;
        } else {
            this.tail.next = newNode;
            this.tail = newNode;
        }
        this._size++;
    }

    isEmpty() {
        return this._size === 0;
    }

    pop() {
        if (this.isEmpty()) return null;
        const value = this.head.value;
        this.head = this.head.next;
        this._size--;
        return value;
    }

    peek() {
        if (this.isEmpty()) return null;
        return this.head.value;
    }
    
    size() {
        return this._size;
    }
}
